home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / MoreFiles 1.2.1 / DirectoryCopy.p < prev    next >
Encoding:
Text File  |  1994-07-22  |  6.9 KB  |  163 lines  |  [TEXT/PJMM]

  1. UNIT DirectoryCopy;
  2.  
  3. {    Apple Macintosh Developer Technical Support                                }
  4. {                                                                            }
  5. {    DirectoryCopy: A robust, general purpose directory copy routine.        }
  6. {    by Jim Luther, Apple Developer Technical Support                        }
  7. {                                                                            }
  8. {    File:        DirectoryCopy.p                                                }
  9. {                                                                            }
  10. {    Copyright © 1992-1994 Apple Computer, Inc.                                }
  11. {    All rights reserved.                                                    }
  12. {                                                                            }
  13. {    You may incorporate this sample code into your applications without        }
  14. {    restriction, though the sample code has been provided "AS IS" and the    }
  15. {    responsibility for its operation is 100% yours.  However, what you are    }
  16. {    not permitted to do is to redistribute the source as "DSC Sample Code"    }
  17. {    after having made changes. If you're going to re-distribute the source,    }
  18. {    we require that you make it clear in the source that the code was        }
  19. {    descended from Apple Sample Code, but that you've made changes.            }
  20.  
  21.  
  22. INTERFACE
  23.  
  24. {***************************************************************************}
  25.  
  26.     { DirectoryCopy failedOperation codes. }
  27.     CONST
  28.         getNextItemOp = 1;            { couldn't access items in this }
  29.                                     { directory - no access privileges }
  30.         copyDirCommentOp = 2;        { couldn't copy directory's Finder }
  31.                                     { comment }
  32.         copyDirAccessPrivsOp = 3;    { couldn't copy directory's AFP access }
  33.                                     { privileges }
  34.         copyDirFMAttributesOp = 4;    { couldn't copy directory's File }
  35.                                     { Manager attributes }
  36.         dirCreateOp = 5;            { couldn't create destination directory }
  37.         fileCopyOp = 6;                { couldn't copy file }
  38.  
  39.  
  40. {***************************************************************************}
  41.  
  42.     TYPE
  43.         CopyErrProcPtr = ProcPtr;
  44.  
  45. {    A DirectoryCopy CopyErrProc function should have the following form:    }
  46. {                                                                            }
  47. {    FUNCTION MyCopyErrProc (error: OSErr;                                     }
  48. {                            failedOperation: Integer;                        }
  49. {                            srcVRefNum: Integer;                            }
  50. {                            srcDirID: LongInt;                                }
  51. {                            srcName: StringPtr;                                }
  52. {                            dstVRefNum: Integer;                            }
  53. {                            dstDirID: LongInt;                                }
  54. {                            dstName: StringPtr): Boolean;                    }
  55. {                                                                            }
  56. {    DirectoryCopy will call your CopyErrProc function if an error condition    }
  57. {    is detected sometime during the copy.  If your CopyErrProc returns        }
  58. {    true, then DirectoryCopy attempts to continue with the directory copy    }
  59. {    operation.  If your CopyErrProc returns false, then DirectoryCopy stops    }
  60. {    the directory copy operation.                                            }
  61. {                                                                            }
  62. {    error            input:    The error result code that caused CopyErrProc    }
  63. {                            to be called.                                    }
  64. {    failedOperation    input:    The operation that returned an error to            }
  65. {                            DirectoryCopy.                                    }
  66. {    srcVRefNum        input:    Source volume specification.                    }
  67. {    srcDirID        input:    Source directory ID.                            }
  68. {    srcName            input:    Source file or directory name, or nil if        }
  69. {                            srcDirID specifies the directory.                }
  70. {    dstVRefNum        input:    Destination volume specification.                }
  71. {    dstDirID        input:    Destination directory ID.                        }
  72. {    dstName            input:    Destination file or directory name, or nil if    }
  73. {                            dstDirID specifies the directory.                }
  74.  
  75.  
  76. {***************************************************************************}
  77.  
  78.  
  79.     FUNCTION DirectoryCopy (srcVRefNum: Integer;
  80.                                     srcDirID: LongInt;
  81.                                     srcName: StringPtr;
  82.                                     dstVRefNum: Integer;
  83.                                     dstDirID: LongInt;
  84.                                     dstName: StringPtr;
  85.                                     copyBufferPtr: Ptr;
  86.                                     copyBufferSize: LongInt;
  87.                                     preflight: Boolean;
  88.                                     copyErrHandler: CopyErrProcPtr): OSErr;
  89. {    Use DirectoryCopy to make a copy of a directory structure in a new        }
  90. {    location.  If copyBufferPtr <> NIL, it points to a buffer of            }
  91. {    copyBufferSize that is used to copy files data.  The larger the            }
  92. {    supplied buffer, the faster the copy.  If copyBufferPtr = NIL, then        }
  93. {    this routine allocates a buffer in the application heap. If you pass a    }
  94. {    copy buffer to this routine, make its size a multiple of 512            }
  95. {    ($200) bytes for optimum performance.                                    }
  96. {                                                                            }
  97. {    srcVRefNum        input:    Source volume specification.                    }
  98. {    srcDirID        input:    Source directory ID.                            }
  99. {    srcName            input:    Source directory name, or nil if                }
  100. {                            srcDirID specifies the directory.                }
  101. {    dstVRefNum        input:    Destination volume specification.                }
  102. {    dstDirID        input:    Destination directory ID.                        }
  103. {    dstName            input:    Destination directory name, or nil if            }
  104. {                            dstDirID specifies the directory.                }
  105. {    copyBufferPtr    input:    Points to a buffer of copyBufferSize that        }
  106. {                            is used the i/o buffer for the copy or            }
  107. {                            nil if you want DirectoryCopy to allocate its    }
  108. {                            own buffer in the application heap.                }
  109. {    copyBufferSize    input:    The size of the buffer pointed to                }
  110. {                            by copyBufferPtr.                                }
  111. {    preflight        input:    If true, DirectoryCopy makes sure there are        }
  112. {                            enough allocation blocks on the destination        }
  113. {                            volume to hold the directory's files before        }
  114. {                            starting the copy.                                }
  115. {    copyErrHandler    input:    A pointer to the routine you want called if an    }
  116. {                            error condition is detected during the copy, or    }
  117. {                            nil if you don't want to handle error            }
  118. {                            conditions. Error handling is recommended...    }
  119.  
  120.  
  121. {***************************************************************************}
  122.  
  123.  
  124.     FUNCTION FSpDirectoryCopy (srcSpec: FSSpec;
  125.                                     dstSpec: FSSpec;
  126.                                     copyBufferPtr: Ptr;
  127.                                     copyBufferSize: LongInt;
  128.                                     preflight: Boolean;
  129.                                     copyErrHandler: CopyErrProcPtr): OSErr;
  130. {    Use FSpDirectoryCopy to make a copy of a directory structure in a new    }
  131. {    location.  If copyBufferPtr <> NIL, it points to a buffer of            }
  132. {    copyBufferSize that is used to copy files data.  The larger the            }
  133. {    supplied buffer, the faster the copy.  If copyBufferPtr = NIL, then        }
  134. {    this routine allocates a buffer in the application heap. If you pass a    }
  135. {    copy buffer to this routine, make its size a multiple of 512            }
  136. {    ($200) bytes for optimum performance.                                    }
  137. {                                                                            }
  138. {    srcSpec            input:    An FSSpec record specifying the directory to    }
  139. {                            copy.                                            }
  140. {    dstSpec            input:    An FSSpec record specifying destination            }
  141. {                            directory of the copy.                            }
  142. {    copyBufferPtr    input:    Points to a buffer of copyBufferSize that        }
  143. {                            is used the i/o buffer for the copy or            }
  144. {                            nil if you want DirectoryCopy to allocate its    }
  145. {                            own buffer in the application heap.                }
  146. {    copyBufferSize    input:    The size of the buffer pointed to                }
  147. {                            by copyBufferPtr.                                }
  148. {    preflight        input:    If true, FSpDirectoryCopy makes sure there are    }
  149. {                            enough allocation blocks on the destination        }
  150. {                            volume to hold the directory's files before        }
  151. {                            starting the copy.                                }
  152. {    copyErrHandler    input:    A pointer to the routine you want called if an    }
  153. {                            error condition is detected during the copy, or    }
  154. {                            nil if you don't want to handle error            }
  155. {                            conditions. Error handling is recommended...    }
  156.  
  157.  
  158. {***************************************************************************}
  159.  
  160.  
  161. IMPLEMENTATION
  162.  
  163. END.